import { defineStore } from 'pinia';
import * as orderApi from '@/api/order';

export const useOrderStore = defineStore('order', () => {
	async function getOrders(param?: any) {
		uni.showLoading();
		const response = await orderApi.getOrders(param);
		uni.hideLoading();
		if (response.code === 20000) {
			return response.data.orders;
		}
		return [];
	}

	async function createOrder(param?: any) {
		uni.showLoading();
		const response = await orderApi.createOrder(param);
		uni.hideLoading();
		return response.data;
	}

	async function getConfirmOrder(param?: any) {
		uni.showLoading();
		const response = await orderApi.getConfirmOrder(param);
		uni.hideLoading();
		return response.data;
	}

	return {
		getOrders,
		createOrder,
		getConfirmOrder
	};
});
